React = require('react')
Card = require('antd-mobile/lib/card')
# ListView = require('antd-mobile/lib/list-view')
Flex = require('antd-mobile/lib/flex')
Icon = require('antd-mobile/lib/icon')
Toast = require('antd-mobile/lib/toast')
RefreshControl = require('antd-mobile/lib/refresh-control')
{View,Image,Text,ScrollView,TouchableHighlight,StyleSheet,Navigator,ListView,TouchableOpacity} = require('react-native')
Dimensions = require('Dimensions')
{ width, height } = Dimensions.get('window')
{View} = require('react-native')
{fetchGetList,fetchRefreshList} = require('../actions/page_dddbrz.js')
{connect} = require('react-redux')
_ = require('underscore')

backImg = require('../img/back.png')
searchIcon = require('../img/search_white.png')

Page_Ckblbg = React.createClass
  getInitialState:->
    {}
  refreshList:->
    Toast.loading('数据重新加载中')
    @props.fetchRefresh()
  backClickHandle:->
    {navigator} = @props
    home =  _.findWhere navigator.getCurrentRoutes(),{name:"Home"}
    navigator.jumpTo home
  componentDidMount:->
    setTimeout =>
      debugger
      if @props.lastFetchTime
        lastTime = moment(@props.lastFetchTime)
        currTime = moment(new Date())
        dura = moment.duration(1,'days')
        if currTime.subtract(dura).isAfter(lastTime)
          @props.fetchGet(@props.pageIndex+1)
      else
        @props.fetchGet(@props.pageIndex+1)
    ,600
  componentWillMount:->

    # navigator.setOnNavigatorEvent ->
    #   that.props.fetchGet(1)
  componentWillUpdate:(nextProp)->
    unless nextProp.isLoading
      Toast.hide()
  render:->
    model = @props.list[0] ? {}
    <View style={width:width,height:height,flexDirection:'column'}>
      <View style={{flexDirection:'row',flex:0,height:60,alignItems:'center', justifyContent:'center',backgroundColor:'#0066FF'}}>
        <View style={{flex:1,padding:10}}>
          <TouchableOpacity onPress={@backClickHandle}>
            <Image source={backImg}  style={{height:30,width:30,resizeMode:'contain'}}/>
          </TouchableOpacity>
        </View>
        <View style={{flex:3,justifyContent:'center',alignItems:'center'}}>
          <Text style={{fontSize:20,color:'#ffffff'}}>调度当班日志</Text>
        </View>
        <View style={{flex:1,alignItems:'flex-end',padding:10}}>
        </View>
      </View>
      <ScrollView style={{flexDirection:'column',backgroundColor:'#ffffff',paddingTop:10}}>
        <View style={styles.rowContainer}>
          <View style={styles.leftContainer}>
            <Text style={styles.leftText}>值班领导</Text>
          </View>
          <View style={styles.rightContainer}>
            <Text style={styles.rightText}>{model.CHEXECUTIVE1 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHEXECUTIVE2 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHEXECUTIVE3 ? ''}</Text>
          </View>
        </View>
        <View style={styles.rowContainer}>
          <View style={styles.leftContainer}>
            <Text style={styles.leftText}>正班</Text>
          </View>
          <View style={styles.rightContainer}>
            <Text style={styles.rightText}>{model.CHZHENG1 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHZHENG2 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHZHENG3 ? ''}</Text>
          </View>
        </View>
        <View style={styles.rowContainer}>
          <View style={styles.leftContainer}>
            <Text style={styles.leftText}>副班</Text>
          </View>
          <View style={styles.rightContainer}>
            <Text style={styles.rightText}>{model.CHFU1 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHFU2 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHFU3 ? ''}</Text>
          </View>
        </View>
        <View style={styles.rowContainer}>
          <View style={styles.leftContainer}>
            <Text style={styles.leftText}>夜班</Text>
          </View>
          <View style={styles.rightContainer}>
            <Text style={styles.rightText}>{model.CHNIGHT1 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHNIGHT2 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHNIGHT3 ? ''}</Text>
          </View>
        </View>
        <View style={styles.rowContainer}>
          <View style={styles.leftContainer}>
            <Text style={styles.leftText}>联合办公</Text>
          </View>
          <View style={styles.rightContainer}>
            <Text style={styles.rightText}>{model.CHJIAN1 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHJIAN2 ? ''}</Text>
            <Text style={styles.rightText}>{model.CHJIAN3 ? ''}</Text>
          </View>
        </View>
        <View style={styles.rowContainer}>
          <View style={styles.leftContainer}>
            <Text style={styles.leftText}>长江</Text>
          </View>
          <View style={styles.rightContainer}>
            <Text style={styles.rightText}>{model.CHCHANG1 ? ''}</Text>
            <Text style={styles.rightText} style={styles.rightText}>{model.CHCHANG2 ? ''}</Text>
            <Text style={styles.rightText} style={styles.rightText}>{model.CHCHANG3 ? ''}</Text>
          </View>
        </View>
      </ScrollView>
    </View>

styles = StyleSheet.create
  rowContainer:
    flexDirection:'row'
    paddingBottom:10
  leftContainer:
    backgroundColor:'#90d7ec'
    width:150
    flexDirection:'column'
    justifyContent:'center'
    alignItems:'center'
  rightContainer:
    backgroundColor:'#ffffff'
    flexDirection:'column'
    justifyContent:'center'
    alignItems:'center'
    flex:1
  leftText:
    color:'#ffffff'
    fontSize:30
  rightText:
    color:'#000000'
    fontSize:20

mapStateToProps = (state)->
  list:state.page_dddbrz.list
  isLoading:state.page_dddbrz.isLoading
  completed:state.page_dddbrz.completed
  refreshing:state.page_dddbrz.refreshing
mapDispatchToProps = (dispatch,wonProps)->
  fetchGet:()->
    dispatch fetchGetList()
  fetchRefresh:->
    dispatch fetchRefreshList()

module.exports = connect(mapStateToProps,mapDispatchToProps)(Page_Ckblbg)
